 <?php
   $currentUser = $this->Session->read('Auth.User');
   $title = $data['Content']['title'];
   $preview = _encode(array('id'=>$data['Content']['id'],'opr'=>'preview'));
   $delete = _encode(array('id'=>$data['Content']['id'],'opr'=>'delete'));
 ?>
 <link href="<?php echo Router::url('/', true); ?>css/bootstrap-wysihtml5/bootstrap3-wysihtml5.min.css" rel="stylesheet" type="text/css" />
 <link href="<?php echo Router::url('/', true); ?>css/daterangepicker/daterangepicker-bs3.css" rel="stylesheet" type="text/css" />
 <div class="row">
   <div class="col-md-12">
        <!-- Custom Tabs -->
        <div class="nav-tabs-custom">
            <ul class="nav nav-tabs">
               <li class="<?php echo $tab == 'basic' ? 'active' : '' ?>"><?php echo $this->Html->link(__('Basic'),array('controller'=>'video','action'=>'videoopr/basic','?'=>$this->request->query)) ?></li>
               <li class="<?php echo $tab == 'advanced' ? 'active' : '' ?>"><?php echo $this->Html->link(__('Advanced'),array('controller'=>'video','action'=>'videoopr/advanced','?'=>$this->request->query)) ?></li>
               <!-- <li class="<?php echo $tab == 'caption' ? 'active' : '' ?>"><?php echo $this->Html->link(__('Captions'),array('controller'=>'video','action'=>'videoopr/caption','?'=>$this->request->query)) ?></li> -->
               <!-- <li class="<?php echo $tab == 'scheduling' ? 'active' : '' ?>"><?php echo $this->Html->link(__('Scheduling'),array('controller'=>'video','action'=>'videoopr/scheduling','?'=>$this->request->query)) ?></li> -->
               <li class="<?php echo $tab == 'availability' ? 'active' : '' ?>"><?php echo $this->Html->link(__('Availability'),array('controller'=>'video','action'=>'videoopr/availability','?'=>$this->request->query)) ?></li>
               <li class="<?php echo $tab == 'thumbnail' ? 'active' : '' ?>"><?php echo $this->Html->link(__('Thumbnail'),array('controller'=>'video','action'=>'videoopr/thumbnail','?'=>$this->request->query)) ?></li>
               <li class="<?php echo $tab == 'promo' ? 'active' : '' ?>"><?php echo $this->Html->link(__('Promo'),array('controller'=>'video','action'=>'videoopr/promo','?'=>$this->request->query)) ?></li>
               <li class="<?php echo $tab == 'flavors' ? 'active' : '' ?>"><?php echo $this->Html->link(__('Flavors'),array('controller'=>'video','action'=>'videoopr/flavors','?'=>$this->request->query)) ?></li>
               <li class="pull-right">
                  <a class="dropdown-toggle" data-toggle="dropdown" href="#">
                     <?=__('Action')?><span class="caret"></span>
                  </a>
                  <ul class="dropdown-menu">
                        <li><a href="javascript:void(0)" id="<?php echo $preview ?>" class="preview"><?=__('Preview')?></a></li>
                        <li><?php echo $this->Html->link(__('Delete'),array('controller'=>'video','action'=>'videoopr','?'=>array('action'=>$delete)),array('class'=>'confirm','message'=>'Are you sure to delete Video')); ?></li>
                        <li><a href="<?=$back?>"><?=__('Back')?></a></li>
                  </ul>
               </li>
            </ul>
            <div class="tab-content">
<!-- 
********************************************************************************************
Basic Section
********************************************************************************************
-->
<?php if($tab == 'basic') { //echo '<pre>';print_r($data);echo '</pre>'; ?>
                <div class="tab-pane active" id="tab_1">
                        <?php echo $this->Form->create('contents', array('url' => array('controller' => 'video', 'action' => 'videoopr/basic','?'=>$this->request->query))); ?>
                        <div class="box box-solid">
                           <div class="box-body">
                              <div class="row">
                                  <div class="form-group col-lg-6">
                                       <?php echo $this->Form->hidden('id'); ?>
                                       <?php echo $this->Form->hidden('user_id'); ?>
                                       <?php echo $this->Form->hidden('type'); ?>
                                       <?php echo $this->Form->input('title',array('class'=>'form-control','placeholder'=>__('Title'),'label'=>__('Title'))); ?>
                                  </div>
                                  <div class="form-group col-lg-6">
                                       <?php echo $this->Form->input('category',array('options'=>$category,'class'=>'form-control','label'=>__('Category'),'empty' =>__('Select'))); ?>
                                  </div>
                                  <div class="form-group col-lg-12">
                                       <?php echo $this->Form->input('description',array('class'=>'textarea','type'=>'textarea','placeholder'=>__('Description'),'label'=>__('Description'),'style'=>'width: 100%; height: 200px; font-size: 14px; line-height: 18px; border: 1px solid #dddddd; padding: 10px;')); ?>
                                  </div>
                                  <div class="form-group col-lg-12">
                                       <?php echo $this->Form->input('keywords',array('class'=>'form-control keywords_tag','placeholder'=>__('Keywords'),'label'=>__('Keywords'))); ?>
                                  </div>
                                  <div class="form-group col-lg-12">
                                    <label><?php echo $this->Form->checkbox('status',array('class'=>'form-control','label'=>false)); ?>&nbsp;<?php echo __('Status'); ?></label>
                                  </div>
                              </div>
                           </div>
                           <div class="box-footer">
                              <button class="btn btn-primary btn-sm" type="submit"><?php echo __('Save'); ?></button>
                           </div>
                        </div>
                        </form>
                </div>
<?php } ?>            
<!-- 
********************************************************************************************
Advance Section
********************************************************************************************
-->                               
<?php if($tab == 'advanced') { ?>                
                <div class="tab-pane active" id="tab_2">
                     <div class="row">
                        <div class="col-md-6">
                           <div class="box box-solid">
                              <div class="box-body">
                                <div id="renderPlayer"></div>
                                <?php echo $this->requestAction(array('controller' => 'video', 'action' => 'renderJwPlayer/renderPlayer/5')); ?>
                              </div>
                           </div>
                        </div>
                        <div class="col-md-6">
                           <div class="box box-solid">
                               <div class="box-body">
                                 <div class="box-group" id="accordion">
                                        <div class="panel box box-solid">
                                            <div class="box-header">
                                                <h4 class="box-title">
                                                    <a data-toggle="collapse" data-parent="#accordion" href="#collapseOne">
                                                        Video Adds
                                                    </a>
                                                </h4>
                                            </div>
                                            <div id="collapseOne" class="panel-collapse collapse in">
                                                <div class="box-body" style="height: 200px; overflow-y: scroll;">
                                                   <table class="table">
                                                      <tr>
                                                          <th style="width: 10px">#</th>
                                                          <th>Title</th>
                                                          <th>Preview</th>
                                                          <th>Offset</th>
                                                      </tr>
                                                      <?php for($i=0;$i<=10;$i++) { ?>
                                                      <tr>
                                                          <td><input type="checkbox" /></td>
                                                          <td>Jabong Adds</td>
                                                          <td><a href="#">Preview</a></td>
                                                          <td>03:26:56</td>
                                                      </tr>
                                                      <?php } ?>
                                                   </table>
                                                </div>
                                            </div>
                                        </div>
                                        <div class="panel box box-solid">
                                            <div class="box-header">
                                                <h4 class="box-title">
                                                    <a data-toggle="collapse" data-parent="#accordion" href="#collapseTwo">
                                                        Banner Adds
                                                    </a>
                                                </h4>
                                            </div>
                                            <div id="collapseTwo" class="panel-collapse collapse">
                                                <div class="box-body" style="height: 200px; overflow-y: scroll;">
                                                   <table class="table">
                                                      <tr>
                                                          <th style="width: 10px">#</th>
                                                          <th>Title</th>
                                                          <th>Preview</th>
                                                          <th>Position</th>
                                                          <th>Offset</th>
                                                      </tr>
                                                      <?php for($i=0;$i<=10;$i++) { ?>
                                                      <tr>
                                                          <td><input type="checkbox" /></td>
                                                          <td>Jabong Adds</td>
                                                          <td><a href="#">Preview</a></td>
                                                          <td><select><option>Select</option></select></td>
                                                          <td>03:26:56</td>
                                                      </tr>
                                                      <?php } ?>
                                                   </table>
                                                </div>
                                            </div>
                                        </div>
                                        <div class="panel box box-solid">
                                            <div class="box-header">
                                                <h4 class="box-title">
                                                    <a data-toggle="collapse" data-parent="#accordion" href="#collapseThree">
                                                        Custom Adds
                                                    </a>
                                                </h4>
                                            </div>
                                            <div id="collapseThree" class="panel-collapse collapse">
                                                <div class="box-body">
                                                   <button type="submit" class="btn btn-default btn-sm">Upload Vast File</button>
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                               </div>
                              <div class="box-footer">
                                 <button class="btn btn-primary btn-sm" type="submit">Save</button>
                                 <button class="btn btn-primary btn-sm" type="submit">Preview</button>
                                 <button class="btn btn-primary btn-sm" type="submit">Reset</button>
                              </div>
                           </div>
                        </div>
                     </div>
                </div>
<?php } ?> 
<!-- 
********************************************************************************************
Availability Section
********************************************************************************************
-->
<?php if($tab == 'availability') { ?>
                <div class="tab-pane active" id="tab_3">
                     <div class="box box-solid">
                        <div class="box-body">
                           <div class="row">
                              <div class="col-lg-12">                                    
                                  <label>
                                      <input type="radio" name="r2" class="minimal-red" checked/>
                                      Always
                                  </label>
                                  &nbsp;&nbsp;&nbsp;
                                  <label>
                                      <input type="radio" name="r2" class="minimal-red"/>
                                      Period
                                  </label>
                              </div>
                           </div>
                        </div>
                        <div class="box-body " id="datepanal">
                           <div class="row">
                              <div class="form-group col-lg-6">                                    
                                 <label>Start Date</label>
                                 <input name="content_title" class="form-control" id="content_title" type="text" placeholder="Start Date" />
                              </div>
                              <div class="form-group col-lg-6">                                    
                                 <label>End Date</label>
                                 <input name="content_title" class="form-control" id="content_title" type="text" placeholder="End Date" />
                              </div>
                           </div>
                        </div>
                        <div class="box-footer">
                           <button class="btn btn-primary btn-sm" type="submit">Save</button>
                        </div>
                     </div>
                </div>
<?php } ?>
<!-- 
********************************************************************************************
Thumbnail Section
********************************************************************************************
-->
<?php if($tab == 'thumbnail') { ?>
         <div class="tab-pane active" id="tab_4">
           <div class="row">
              <div class="col-md-12">
                 <div class="box box-solid">
                    <div class="box-header">
                        <div class="box-tools">
                           <button data-toggle="dropdown" class="btn btn-warning" type="button">Add Thumbnail&nbsp;&nbsp;<span class="fa fa-caret-down"></span></button>
                           <ul class="dropdown-menu">
                                 <li role="presentation"><a href="javascript:void(0)" data-toggle="modal" data-backdrop="false" data-target="#uploadThumb">Upload</a></li>
                                 <li role="presentation"><a href="javascript:void(0)" data-toggle="modal" data-backdrop="false" data-target="#cropThumb">New Crop</a></li>
                                 <li role="presentation"><a href="javascript:void(0)" data-toggle="modal" data-backdrop="false" data-target="#grabThumb">Grab from Video</a></li>
                           </ul> 
                        </div>
                     </div>
                    <div class="box-body">
                        <table class="table">
                           <tr>
                               <th style="width: 2%">#</th>
                               <th style="width: 22%">Thumbnail</th>
                               <th style="width: 12.5%">Name</th>
                               <th style="width: 12.5%">Type</th>
                               <th style="width: 12.5%">Dimensions</th>
                               <th style="width: 12.5%">Size [KB]</th>
                               <th style="width: 26%">Action</th>
                           </tr>
                           <?php
                              $counter = 0;
                              foreach($thumbnails as $key=>$val){
                                 if(isset($val['f']['info'])){
                                    $tmp = unserialize(base64_decode($val['f']['info']));
                                    $td = sprintf('<td>%s</td>',++$counter);
                                    $td .= sprintf('<td><img width="100px" height="100px" src="%s"></td>',Router::url('/', true).$val['f']['relative_path']);
                                    $td .= sprintf('<td>%s</td>',$tmp['filename']);
                                    $td .= sprintf('<td>%s</td>',$tmp['mime_type']);
                                    $td .= sprintf('<td>%s</td>',$tmp['video']['resolution_x'].'*'.$tmp['video']['resolution_y']);
                                    $td .= sprintf('<td>%s</td>',_byteFormat($tmp['filesize']));
                                    
                                    $setAsDefault = _encode(array('id'=>$val['vt']['id'],'content_id'=>$data['Content']['id'],'opr'=>'thumbmail_set_as_default','thumbnail_id'=>$val['f']['id'],'queryString'=>$this->request->query));
                                    $download = _encode(array('id'=>$val['vt']['id'],'content_id'=>$data['Content']['id'],'opr'=>'thumbmail_download','thumbnail_id'=>$val['f']['id'],'queryString'=>$this->request->query));
                                    $delete = _encode(array('id'=>$val['vt']['id'],'content_id'=>$data['Content']['id'],'opr'=>'thumbmail_delete','thumbnail_id'=>$val['f']['id'],'queryString'=>$this->request->query));
                                    
                                    $tmpClassDefault = isset($val['vt']['default_thumbnail'])  && $val['vt']['default_thumbnail'] == 1 ? 'btn btn-default btn-sm disabled' : 'btn btn-info btn-sm';
                                    $tmpClassDelete = isset($val['vt']['default_thumbnail'])  && $val['vt']['default_thumbnail'] == 1 ? 'btn btn-default btn-sm disabled' : 'btn btn-danger btn-sm confirm';
                              ?>
                              <tr>
                               <?php echo $td; ?>  
                               <td>
                                 <?php echo $this->Html->link('Set as Default',array('controller'=>'video','action'=>'videoopr/thumbnail','?'=>array('action'=>$setAsDefault)),array('class'=>$tmpClassDefault)) ?>
                                 <?php echo $this->Html->link('Download',array('controller'=>'video','action'=>'videoopr/thumbnail','?'=>array('action'=>$download)),array('class'=>'btn btn-success btn-sm')) ?>
                                 <?php echo $this->Html->link('Delete',array('controller'=>'video','action'=>'videoopr/thumbnail','?'=>array('action'=>$delete)),array('class'=>$tmpClassDelete)) ?>
                               </td>
                           </tr>
                           <?php }} ?>
                        </table>
                    </div><!-- /.box-body -->
                 </div>
              </div>
           </div>
         </div>
         
         <!-- Modelbox start upload image -->
         <div class="modal fade" id="uploadThumb">
         <div class="modal-dialog">
         <div class="modal-content">
            <div class="modal-header">
             <button type="button" class="close" data-dismiss="modal">
                 <span aria-hidden="true">&times;</span>
                 <span class="sr-only">Close</span>
             </button>
             <h4 id="modelbox_title">Thumbnail: Upload</h4>
            </div>
            <?php echo $this->Form->create('uploadthumb', array('url' => array('controller' => 'video', 'action' => 'videoopr/thumbnail','?'=>array('action'=>_encode(array('id'=>$data['Content']['id'],'opr'=>'uploadthumbnail')))),'type'=>'file')); ?>
            <div class="modal-body">
               <button id="uploadThumbnail" type="button" class="btn btn-default btn-sm">Choose Thumbnail</button>
               <?php
                  echo $this->Form->hidden('content_id',array('value'=>$data['Content']['id']));
                  echo $this->Form->file('file',array('multiple'=>false,'style'=>'display:none;','accept'=>'image/*','name'=>'uploadthumbfile'));
               ?>
            </div>
            <div class="progress sm progress-striped hide" style="margin-bottom:-16px" id="thumbnail_process">
               <div class="progress-bar progress-bar-danger"></div>
            </div>
            <div class="modal-footer">
               <button type="submit" class="btn btn-primary">Upload</button>
               <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
            </div>
            <?php echo $this->Form->end(); ?>
         </div>
         </div>
         </div>
         <!-- Modelbox end -->
         <?php
            $style = $image = null;
            if(isset($default_image)){
               list($width, $height, $type, $attr) = getimagesize($default_image['absolute_path']);
               $width = $width > 600 ? 600 : $width;
               $height = $height > 400 ? 400 : $height;
               $style = sprintf('style="width:%dpx;height:%dpx"',$width + 2,$height);
               $image = $this->Html->image(Router::url('/', true).$default_image['relative_path'],array('id'=>'cropThumbnailBody','width'=>$width,'height'=>$height));
            }else{
               $image = 'Please select thumbnail as a Default';
            }
         ?>
         
         <!-- Inculde Crop css -->
         <link href="<?php echo Router::url('/', true); ?>css/jcrop.css" rel="stylesheet" type="text/css" />
         <!-- Modelbox start Crop image -->
         <div class="modal fade" id="cropThumb">
         <div class="modal-dialog" <?=$style?>>
         <div class="modal-content">
           <div class="modal-header">
             <button type="button" class="close" data-dismiss="modal">
                 <span aria-hidden="true">&times;</span>
                 <span class="sr-only">Close</span>
             </button>
             <h4 id="modelbox_title">Thumbnail: Crop</h4>
           </div>
           <div class="modal-body text-center no-padding"><?=$image?></div>
            <?php echo $this->Form->create('thumbnailcrop', array('url' => array('controller' => 'video', 'action' => 'videoopr/thumbnail','?'=>$this->request->query))); ?>
            <?php echo $this->Form->hidden('file_id',array('value'=>$default_image['id'])); ?>
            <?php echo $this->Form->hidden('x'); ?>
            <?php echo $this->Form->hidden('y'); ?>
            <?php echo $this->Form->hidden('w'); ?>
            <?php echo $this->Form->hidden('h'); ?>
            <div class="modal-footer">
               <button type="submit" class="btn btn-primary">Crop</button>
               <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
            </div>
            <?php echo $this->Form->end(); ?>
         </div>
         </div>
         </div>

         <!-- Inculde Crop javascript -->
         <script src="<?php echo Router::url('/', true); ?>js/jcrop.js" type="text/javascript"></script>
         <script>
            $(function(){
               $('#cropThumbnailBody').Jcrop({
                  aspectRatio: 1,
                  onChange: updatePreview,
                  onSelect: updatePreview,
               });
               
               function updatePreview(c) {
                  $('#thumbnailcropX').val(c.x);
                  $('#thumbnailcropY').val(c.y);
                  $('#thumbnailcropW').val(c.w);
                  $('#thumbnailcropH').val(c.h);
               }
            });
         </script>
         <!-- Modelbox end -->
         
         <!-- Modelbox Grob thumbnail from video -->
         <div class="modal fade" id="grabThumb">
         <div class="modal-dialog">
         <div class="modal-content">
           <div class="modal-header">
             <button type="button" class="close" data-dismiss="modal">
                 <span aria-hidden="true">&times;</span>
                 <span class="sr-only">Close</span>
             </button>
             <h4 id="modelbox_title">Thumbnail: Grab from Video</h4>
           </div>
           <?php echo $this->Form->create('thumbnailgrab', array('url' => array('controller' => 'video', 'action' => 'videoopr/thumbnail','?'=>$this->request->query))); ?>
           <?php echo $this->Form->hidden('seconds'); ?>
           <div class="modal-body text-center no-padding">
               <div id="grabVideoThumbnail"></div>
               <?php echo $this->requestAction(array('controller' => 'video', 'action' => sprintf('renderJwPlayer/grabVideoThumbnail/%d/598/360',$data['Content']['id']))); ?>
            </div>
            <div class="modal-footer" style="margin-top:0px;">
               <button type="submit" class="btn btn-primary">Grab Thumbnail</button>
               <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
            </div>
            <?php echo $this->Form->end(); ?>
         </div>
         </div>
         </div>
         
         
         
         <!-- Modelbox end -->
         
<?php } ?>            
<!-- 
********************************************************************************************
Trailer Section
********************************************************************************************
-->
<?php if($tab == 'promo') { ?>
   <div class="tab-pane active" id="tab_4">
           <div class="row">
              <div class="col-md-12">
                 <div class="box box-solid">
                    <div class="box-header">
                        <div class="box-tools">
                           <a href="javascript:void(0)" class="btn btn-warning" data-toggle="modal" data-backdrop="false" data-target="#addPromo">Add Promo</a>
                        </div>
                     </div>
                    <div class="box-body">
                        <table class="table">
                           <tr>
                               <th style="width: 2%">#</th>
                               <th style="width: 22%">Promo</th>
                               <th style="width: 12.5%">Name</th>
                               <th style="width: 12.5%">type</th>
                               <th style="width: 12.5%">Duration</th>
                               <th style="width: 12.5%">Preview</th>
                               <th style="width: 26%">Action</th>
                           </tr>
                           
                           <?php
                              $counter = 0;
                              foreach($promo_video as $key=>$val){
                                 $vid = 'container'.uniqid();
                                 $tmpInfo = _decode($val['video']['info']);
                                 echo '<tr>';
                                 echo sprintf('<td>%d</td>',++$counter);
                                 echo sprintf('<td><img width="100px" height="100px" src="%s"></td>',Router::url('/', true).$val['thumb']['relative_path']);
                                 echo sprintf('<td>%s</td>',$val['video']['name']);
                                 echo sprintf('<td>%s</td>',$val['video']['minetype']);
                                 echo sprintf('<td>%s</td>',$tmpInfo['playtime_string']);
                                 echo sprintf('<td>%s</td>','<a href="">Preview</a>');
                                 
                                 $setAsDefault = _encode(array('id'=>$val['vp']['id'],'content_id'=>$data['Content']['id'],'opr'=>'promo_set_as_default','promo_id'=>$val['video']['id'],'queryString'=>$this->request->query));
                                 $download = _encode(array('id'=>$val['vp']['id'],'content_id'=>$data['Content']['id'],'opr'=>'promo_download','promo_id'=>$val['video']['id'],'queryString'=>$this->request->query));
                                 $delete = _encode(array('id'=>$val['vp']['id'],'content_id'=>$data['Content']['id'],'opr'=>'promo_delete','promo_id'=>$val['video']['id'],'queryString'=>$this->request->query));
                                 
                                 $tmpClassDefault = isset($val['vt']['default_thumbnail'])  && $val['vt']['default_thumbnail'] == 1 ? 'btn btn-default btn-sm disabled' : 'btn btn-info btn-sm';
                                 $tmpClassDelete = isset($val['vt']['default_thumbnail'])  && $val['vt']['default_thumbnail'] == 1 ? 'btn btn-default btn-sm disabled' : 'btn btn-danger btn-sm confirm';
                                 
                                 
                                 echo '<td>';
                                 echo $this->Html->link('Set as Default',array('controller'=>'video','action'=>'videoopr/promo','?'=>array('action'=>$setAsDefault)),array('class'=>$tmpClassDefault)).'&nbsp;';
                                 echo $this->Html->link('Download',array('controller'=>'video','action'=>'videoopr/promo','?'=>array('action'=>$download)),array('class'=>'btn btn-success btn-sm')).'&nbsp;';
                                 echo $this->Html->link('Delete',array('controller'=>'video','action'=>'videoopr/promo','?'=>array('action'=>$delete)),array('class'=>$tmpClassDelete)).'&nbsp;';
                                 echo '</td>';
                                 echo '</tr>';
                              }
                              //echo '<pre>';print_r($promo_video);echo '</pre>';
                           ?>
                           
                        </table>
                    </div><!-- /.box-body -->
                 </div>
              </div>
           </div>
         </div>
         
         <!-- Modelbox Grob thumbnail from video -->
         <div class="modal fade" id="addPromo">
         <div class="modal-dialog">
         <div class="modal-content">
           <div class="modal-header">
             <button type="button" class="close" data-dismiss="modal">
                 <span aria-hidden="true">&times;</span>
                 <span class="sr-only">Close</span>
             </button>
             <h4 id="modelbox_title">Video Promo</h4>
           </div>
           <?php echo $this->Form->create('videopromo', array('url' => array('controller' => 'video', 'action' => 'videoopr/promo','?'=>$this->request->query))); ?>
           
           
           <?php echo $this->Form->hidden('start_time',array('value'=>'00:00:00')); ?>
           <?php echo $this->Form->hidden('end_time',array('value'=>'00:00:00')); ?>
           <div class="modal-body text-center no-padding">
               <div id="promoVideo"></div>
               <?php echo $this->requestAction(array('controller' => 'video', 'action' => sprintf('renderJwPlayer/promoVideo/%d/598/320',$data['Content']['id']))); ?>
               <label id="errorContainer" class="error"></label>
            </div>
            <div class="modal-footer" style="margin-top:-20px;">
               <div id="slider-range"></div>
               <div id="slider-min" class="pull-left btn btn-xs bg-maroon" style="margin-top:14px">00:00:00</div>
               <div id="slider-max" class="btn btn-xs bg-maroon" style="margin-top:14px">00:00:00</div>
            </div>
            <div class="modal-footer" style="margin-top:-10px;">
               <button type="submit" class="btn btn-primary">Cut Promo</button>
               <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
            </div>
            <?php echo $this->Form->end(); ?>
         </div>
         </div>
         </div>
         <script>
            $(function() {
               
               var vidLength = <?php echo isset($fileinfo['playtime_seconds']) ? $fileinfo['playtime_seconds'] : 0 ?>;
               var stimeInFormat = inttotime(0);
               var etimeInFormat = inttotime(vidLength);
               
               $('#videopromoVideooprForm #slider-min').html(stimeInFormat);
               $('#videopromoVideooprForm #slider-max').html(etimeInFormat);
               
               $('#videopromoVideooprForm #videopromoStartTime').val(0);
               $('#videopromoVideooprForm #videopromoEndTime').val(vidLength);
               
               var stime = 0;
               var etime = vidLength;
               $("#slider-range" ).slider({
                  range: true,
                  min: 0,
                  max: vidLength,
                  values: [0,vidLength ],
                  step: 1,
                  slide: function( event, ui ) {
                    
                    stime = ui.values[0];
                    etime = ui.values[1];
                    
                    stimeInFormat = inttotime(ui.values[0]);
                    etimeInFormat = inttotime(ui.values[1]);
                    
                    jwplayer("promoVideo").seek(stime);
                    
                    $('#videopromoVideooprForm #slider-min').html(stimeInFormat);
                    $('#videopromoVideooprForm #slider-max').html(etimeInFormat);
                    
                    $('#videopromoVideooprForm #videopromoStartTime').val(stime);
                    $('#videopromoVideooprForm #videopromoEndTime').val(etime);
                  }
               });
               
               var pauseOnSeek = false;
               jwplayer("promoVideo").onSeek(function(){
                  pauseOnSeek = true;
               });
               
               jwplayer("promoVideo").onTime(function(event){
                  var state = this.getState();
                  var pos = this.getPosition()
                  if (state == 'PLAYING' && pauseOnSeek == true) {
                     this.pause(true);
                     pauseOnSeek = false;
                  }
                  
                  if(event.position >= etime ) {
                     this.stop();
                  }
               });
               
               $('#addPromo').on('hidden.bs.modal', function () {
                  jwplayer("promoVideo").stop();
               });
            });
         </script>
         
<?php } ?>
<!-- 
********************************************************************************************
Flavors Section
********************************************************************************************
-->
<?php if($tab == 'flavors') { ?>
                <div class="tab-pane active" id="tab_5">
                    <div class="box box-solid">
                        <div class="box-body no-padding">
                            <table class="table">
                              <tbody>
                                  <tr>
                                    <?php echo sprintf('<th>%s</th>',__('Device Name')) ?>
                                    <?php echo sprintf('<th>%s</th>',__('Flavor Name')) ?>
                                    <?php echo sprintf('<th>%s</th>',__('Bitrate')) ?>
                                    <?php echo sprintf('<th>%s</th>',__('Video Bitrate')) ?>
                                    <?php echo sprintf('<th>%s</th>',__('Audio Bitrate')) ?>
                                    <?php echo sprintf('<th>%s</th>',__('Resolution')) ?>
                                    <?php echo sprintf('<th>%s</th>',__('Frame Rate').'(FPS)') ?>
                                    <?php echo sprintf('<th>%s</th>',__('Keyframe Rate')) ?>
                                    <?php echo sprintf('<th>%s</th>',__('Preview')) ?>
                                    <?php echo sprintf('<th>%s</th>',__('Status')) ?>
                                    <?php echo sprintf('<th>%s</th>',__('Action')) ?>
                                  </tr>
                                  <?php foreach($flavorData as $key=>$val) {
                                    echo '<tr>';
                                    echo sprintf('<td>%s</td>',$val['f']['device_name']);
                                    echo sprintf('<td>%s</td>',$val['f']['flavor_name']);
                                    echo sprintf('<td>%s</td>',$val['f']['bitrate']);
                                    echo sprintf('<td>%s</td>',$val['f']['video_bitrate']);
                                    echo sprintf('<td>%s</td>',$val['f']['audio_bitrate']);
                                    echo sprintf('<td>%s</td>',$val['f']['width'].'*'.$val['f']['height']);
                                    echo sprintf('<td>%s</td>',$val['f']['frame_rate']);
                                    echo sprintf('<td>%s</td>',$val['f']['keyframe_rate']);
                                    
                                    $cancelLink = _encode(array('id'=>$data['Content']['id'],'opr'=>'setflavor_cancel','flavor_id'=>$val['f']['id'],'queryString'=>$this->request->query));
                                    $deleteLink = _encode(array('id'=>$data['Content']['id'],'opr'=>'setflavor_delete','flavor_id'=>$val['f']['id'],'queryString'=>$this->request->query));
                                    $convertLink = _encode(array('id'=>$data['Content']['id'],'opr'=>'setflavor_convert','flavor_id'=>$val['f']['id'],'queryString'=>$this->request->query));
                                    
                                    $cancel = $this->Html->link(__('Cancel'),array('controller'=>'video','action'=>'videoopr/flavors','?'=>array('action'=>$cancelLink)),array('class'=>'btn btn-warning btn-sm'));
                                    $delete = $this->Html->link(__('Delete'),array('controller'=>'video','action'=>'videoopr/flavors','?'=>array('action'=>$deleteLink)),array('class'=>'btn btn-danger btn-sm'));
                                    $convert = $this->Html->link(__('Convert'),array('controller'=>'video','action'=>'videoopr/flavors','?'=>array('action'=>$convertLink)),array('class'=>'btn btn-primary btn-sm'));
                                    
                                    switch($val['vf']['status']){
                                       case 'inprocess' :
                                          echo sprintf('<td>--</td>');
                                          echo sprintf('<td><span class="label label-primary">%s</span></td>',__('In progress'));
                                          echo sprintf('<td>%s</td>',$cancel);
                                          break;
                                       case 'completed' :
                                          echo sprintf('<td>%s</td>',$this->Html->link('Preview','javascript:void(0)'));
                                          echo sprintf('<td><span class="label label-success">%s</span></td>',__('Completed'));
                                          echo sprintf('<td>%s</td>',$delete);
                                          break;
                                       default :
                                          echo sprintf('<td>--</td>');
                                          echo sprintf('<td><span class="label label-warning">%s</span></td>',__('Pending'));
                                          echo sprintf('<td>%s</td>',$convert);
                                          break;
                                    }
                                    echo '</tr>';
                                  }
                                  ?>
                              </tbody>
                          </table>
                        </div><!-- /.box-body -->
                    </div><!-- /.box -->
                </div>
<?php } ?>
<!-- 
********************************************************************************************
End Flavors Section
********************************************************************************************
-->         </div><!-- /.tab-content -->
        </div><!-- nav-tabs-custom -->
    </div><!-- /.col -->
</div> <!-- /.row -->

<script src="<?php echo Router::url('/', true); ?>js/plugins/bootstrap-wysihtml5/bootstrap3-wysihtml5.all.min.js"></script>
<!-- date-range-picker -->
<script src="<?php echo Router::url('/', true); ?>js/plugins/daterangepicker/daterangepicker.js" type="text/javascript"></script>
<script>
    $(function(){
        $(".textarea").wysihtml5();
        $('#daterange').daterangepicker({timePicker: true, timePickerIncrement: 30, format: 'MM/DD/YYYY h:mm A'});
    });
</script>